///////////////////////////////////////////////////////////////////////////////////
//				The Effects of State Business taxes on Plant Closures: 			 //
//	Evidence from Unemployment Insurance Taxation and Multi-Establishment Firms  //
//							Audrey Guo, May 2021								 //
///////////////////////////////////////////////////////////////////////////////////
clear all
set more off
cd "data folder path here"

***** FIGURE 1 ****************************
** see figures.R file

***** FIGURE 2 ****************************
use 2008.q1-q4.singlefile.dta, clear
keep if qtr==1
keep if aggl==54
keep if ind=="31-33"
gen state = substr(area,1,2)
destring(state), replace
drop if state>56
keep state year avg_wkly
replace avg_wkly = avg_wkly/1000

merge 1:1 state year using uitax.dta
keep if _merge==3
drop _merge
merge 1:1 state year using statecosts.dta
keep if _merge==3
drop _merge
replace maxtax = 2000 if maxtax>2000

label variable maxtax "Maximum Per-Capita UI Tax ($)"
label variable avg_wkly "Avg Weekly Wage ($1000's)"
corr maxtax avg_wkly
local corr: disp %5.4f r(rho)
scatter avg_wkly maxtax || lfit avg_wkly maxtax, note(Corr = `corr') name(a, replace) legend(off) title("Manufacturing Weekly Wage ($1000's)") graphregion(color(white))

label variable corporate_rate "State Corporate Tax Rate (%)"
corr maxtax corp
local corr: disp %5.4f r(rho)
scatter corp maxtax || lfit corp maxtax, note(Corr = `corr') name(b, replace) legend(off) title("State Corporate Tax Rate (%)") graphregion(color(white))

label variable union "Union Membership (%)"
corr maxtax union
local corr: disp %5.4f r(rho)
scatter union maxtax || lfit union maxtax, note(Corr = `corr') name(c, replace) legend(off) title("Union Membership (%)") graphregion(color(white))

label variable wcomp "Index of Workers' Comp Costs (%)"
corr maxtax wcomp
local corr: disp %5.4f r(rho)
scatter wcomp maxtax || lfit wcomp maxtax, note(Corr = `corr') name(d, replace) legend(off) title("Index of Workers' Comp Costs (%)") graphregion(color(white))

graph combine a b c d, graphregion(color(white))

***** FIGURE 3 ****************************
use uitax, clear
merge m:1 year using cpi.dta
keep if _merge==3
drop _merge

gen flex = inlist(state,2,15,16,19,27,30,32,34,35,37,38,40,41,49,53,56)
drop if state==2 | state==15
replace maxtax = maxtax*adj
collapse maxtax, by(flex year)

twoway (line max year if flex==1) (line max year if flex==0, lpattern("-")), legend(label(1 "Flexible Wage Base") label(2 "Other")) scheme(s1color) ytitle("Average Maximum Per-Capita UI Tax (2014 Dollars)") xlabel(1978[3]2014) xtitle("")

***** FIGURE 4 ****************************
use 2002.q1-q4.singlefile.dta, clear
keep if aggl==56
keep if ind=="3371" | ind=="3323" | ind=="3363" | ind=="3261"
forval i = 2003/2014 {
append using `i'.q1-q4.singlefile.dta
keep if aggl==56
keep if ind=="3371" | ind=="3323" | ind=="3363" | ind=="3261"
}
gen state = substr(area,1,2)
destring(state), replace
drop if state>56
rename month3 avgemp
collapse avgemp (count) qtr (sum) qtrly_c, by(state ind year)
gen taxpaid = qtrly_c/avgemp
gen flex = inlist(state,2,15,16,19,27,30,32,34,35,37,38,40,41,49,53,56)

collapse taxpaid avgemp [aw=avgemp], by(ind year flex)
destring(ind), replace
label define labels 3363 "Motor Vehicle Parts" 3261 "Plastics Product" 3371 "Household and Institutional Furniture" 3323 "Architectural and Structural Metals"
label values industry_code labels
label variable taxpaid "Average Per-Capita UI Taxes Paid ($)"

line taxpaid year if flex==1 || line taxpaid year if flex==0, by(ind, note("")) legend(label(1 "Flexible Wage Base") label(2 "Other")) xline(2009) lpattern("-") scheme(s1color)

***** FIGURE 5 ****************************
use exitrates.dta, clear
gen zone = 9
twoway (bar zone year if inrange(year, 2008, 2009), bcolor(gs14) lwidth(none) base(2)) (line exit year) (line exit2 year, lpattern("-#")), by(group, note("")) scheme(s1color) xsize(7) ylabel(2(2)8) xlabel(1997(2)2014) xtitle("") ytitle("Establishment Exit Rate (%)") legend(order(2 3))

***** FIGURES 6-7 ****************************
** see output.do file

//////////////////////////////////////////////////////////////////////////////////////////////
***** APPENDIX FIGURE A.1 ****************************
use 1999.sic.dta, clear
foreach y of numlist 2003 2007 2011 {
append using `y'.q1-q4.singlefile.dta
keep if aggl==56 | year==1999
}
destring(ind), replace
replace ind = n4 if year==1999
keep if ind>3000 & ind<4000
gen state = substr(area,1,2)
destring(state), replace
drop if state>56
keep if disc==""
gen avgemp = month3
collapse avgemp (count) qtr (sum) qtrly_c, by(state ind year)
keep if qtr==4
gen taxpaid = qtrly_c/avgemp

merge m:1 state year using uitax.dta
keep if _merge==3
drop _merge
replace maxtax = 2000 if maxtax>2000

corr maxtax taxpaid if year==1999
local corr: disp %5.4f r(rho)
binscatter taxpaid maxtax if year==1999, note(Corr = `corr') absorb(ind) name(a, replace) scheme(s1color) title("1999")
corr maxtax taxpaid if year==2003
local corr: disp %5.4f r(rho)
binscatter taxpaid maxtax if year==2003, note(Corr = `corr') absorb(ind) name(b, replace) scheme(s1color) title("2003")
corr maxtax taxpaid if year==2007
local corr: disp %5.4f r(rho)
binscatter taxpaid maxtax if year==2007, note(Corr = `corr') absorb(ind) name(c, replace) scheme(s1color) title("2007")
corr maxtax taxpaid if year==2011
local corr: disp %5.4f r(rho)
binscatter taxpaid maxtax if year==2011, note(Corr = `corr') absorb(ind) name(d, replace) scheme(s1color) title("2011")
graph combine a b c d, scheme(s1color)

***** APPENDIX FIGURE A.2 ****************************
use uitax.dta, clear
keep if year==2008
replace maxtax = 2000 if maxtax>2000

reg maxtax benefit
predict resid, residuals
scatter resid maxtax, scheme(s1color)
***** APPENDIX FIGURE A.3 ****************************
** see figures.R file

***** APPENDIX FIGURE A.4 ****************************
use uitax.dta, clear
keep if year==2008
replace maxtax = 2000 if maxtax>2000
corr claimrate maxtax
local corr: display %5.4f r(rho)
scatter claimrate maxtax || lfit claimrate maxtax, note(Corr = `corr') legend(off) ytitle("Initial UI Claims as % of Covered Employment") graphregion(color(white)) xlabel(400[400]2000)

***** APPENDIX FIGURE A.5 ****************************
use jobloss.dta, clear
keep if inlist(n3,315,332,334,336)
bysort n3: egen mean = mean(value)
bysort n3: egen sd = sd(value)
gen zscore = (value - mean)/sd

twoway (line zscore year if n3==315) (line zscore year if n3==332, lpattern("_#")) (line zscore year if n3==334, lpattern("-")) (line zscore year if n3==336, lpattern(".-..")),  legend(label(1 "Clothing") label(2 "Fabricated Metal") label(3 "Computer and Electronics") label(4 "Transportation Equipment")) scheme(s1color) yline(0) xlabel(1998(4)2015) ytitle("Z-score of Industry Job Losses") xtitle("")

***** APPENDIX FIGURE A.6 ****************************
use texas.dta, clear
scatter avgtax cutoff, xtitle("Benefit Ratio (%)") ytitle("Average UI Tax Rate (%)") graphregion(color(white)) yscale(range(7))

***** APPENDIX TABLE A.1 ****************************
use 2000.q1-q4.singlefile.dta, clear
append using 2004.q1-q4.singlefile.dta
append using 2008.q1-q4.singlefile.dta
keep if qtr==1
keep if aggl==54
keep if ind=="31-33"
gen state = substr(area,1,2)
destring(state), replace
drop if state>56
keep state year avg_wkly
replace avg_wkly = avg_wkly/1000
merge 1:1 state year using uitax.dta
keep if _merge==3
drop _merge
merge 1:1 state year using statecosts.dta
keep if _merge==3
drop _merge

estimates clear
eststo: reg maxtax avg_wkly minwage rtw union wcomp corporate_rate rec_val t_pinc_rate republican if year==2000, robust
eststo: reg maxtax avg_wkly minwage rtw union wcomp corporate_rate rec_val t_pinc_rate republican if year==2004, robust
eststo: reg maxtax avg_wkly minwage rtw union wcomp corporate_rate rec_val t_pinc_rate republican if year==2008, robust

esttab using TableA1.tex, replace se coeflabel(avg_wkly_wage "Manufacturing Weekly Wage (\$)" minwage "Minimum Wage (\$)"wcomp "Workers' Comp Index Rate (\%)" rtw "Right-to-Work Status" corporate_rate "Corporate Income Rate (\%)" rec_val "R\&D Tax Credit (\%)" t_pinc_rate "Personal Income Rate (\%)" union "Unionization Rate (\%)" republican "Republican Legislature") r2 obslast star(* 0.10 ** 0.05 *** 0.01)  title(Correlation with Other State Business Costs)

***** APPENDIX TABLES A.2 to A.5 ****************************
** see output.do file